@@ -4,6 +4,7 @@ from __future__ import division  | 
            ||
| 4 | 4 | 
                 | 
            
| 5 | 5 | 
                from django.conf import settings  | 
            
| 6 | 6 | 
                from django.db import transaction  | 
            
| 7 | 
                +from django.db.models import Sum  | 
            |
| 7 | 8 | 
                from django_logit import logit  | 
            
| 8 | 9 | 
                from django_query import get_query_value  | 
            
| 9 | 10 | 
                from django_response import response  | 
            
                @@ -425,16 +426,20 @@ def activity_signin(request):  | 
            ||
| 425 | 426 | 
                })  | 
            
| 426 | 427 | 
                 | 
            
| 427 | 428 | 
                 | 
            
| 428 | 
                -def get_group_share_info_integral(share_user_id, open_gid, group_share_integral):  | 
            |
| 429 | 
                +def get_group_share_info_integral(activity_id, share_user_id, open_gid, group_share_integral, group_share_max_integral):  | 
            |
| 429 | 430 | 
                # 校验该分享人是否已领取该群积分  | 
            
| 430 | 
                - has_integral = MemberActivityGroupShareInfo.objects.filter(share_user_id=share_user_id, open_gid=open_gid, is_integral=True).exists()  | 
            |
| 431 | 
                + has_integral = MemberActivityGroupShareInfo.objects.filter(activity_id=activity_id, share_user_id=share_user_id, open_gid=open_gid, is_integral=True).exists()  | 
            |
| 431 | 432 | 
                if has_integral:  | 
            
| 432 | 433 | 
                return False, 0  | 
            
| 433 | 
                - # TODO: 其他限制条件  | 
            |
| 434 | 
                + # 校验该分享人是否已领取该活动积分上限  | 
            |
| 435 | 
                +    total_integral = MemberActivityGroupShareInfo.objects.filter(activity_id=activity_id, share_user_id=share_user_id).aggregate(Sum('integral')).get('integral__sum', 0) or 0
               | 
            |
| 436 | 
                + if total_integral + group_share_integral > group_share_max_integral:  | 
            |
| 437 | 
                + return False, 0  | 
            |
| 434 | 438 | 
                return True, group_share_integral  | 
            
| 435 | 439 | 
                 | 
            
| 436 | 440 | 
                 | 
            
| 437 | 441 | 
                @logit  | 
            
| 442 | 
                +@transaction.atomic  | 
            |
| 438 | 443 | 
                def activity_group_share(request):  | 
            
| 439 | 444 | 
                     brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
               | 
            
| 440 | 445 | 
                     share_user_id = request.POST.get('share_user_id', '')
               | 
            
                @@ -460,12 +465,12 @@ def activity_group_share(request):  | 
            ||
| 460 | 465 | 
                return response()  | 
            
| 461 | 466 | 
                 | 
            
| 462 | 467 | 
                try:  | 
            
| 463 | 
                - act = MemberActivityInfo.objects.get(activity_id=activity_id, status=True)  | 
            |
| 468 | 
                + act = MemberActivityInfo.objects.select_for_update().get(activity_id=activity_id, status=True)  | 
            |
| 464 | 469 | 
                except MemberActivityInfo.DoesNotExist:  | 
            
| 465 | 470 | 
                return response(MemberActivityStatusCode.ACTIVITY_NOT_FOUND)  | 
            
| 466 | 471 | 
                 | 
            
| 467 | 472 | 
                # 判断是否给积分 & 给多少积分  | 
            
| 468 | 
                - is_integral, integral = get_group_share_info_integral(share_user_id, open_gid, act.group_share_integral)  | 
            |
| 473 | 
                + is_integral, integral = get_group_share_info_integral(act.activity_id, share_user_id, open_gid, act.group_share_integral, act.group_share_max_integral)  | 
            |
| 469 | 474 | 
                 | 
            
| 470 | 475 | 
                     MemberActivityGroupShareInfo.objects.create(**{
               | 
            
| 471 | 476 | 
                'brand_id': act.brand_id,  | 
            
                @@ -479,4 +484,4 @@ def activity_group_share(request):  | 
            ||
| 479 | 484 | 
                'integral': integral,  | 
            
| 480 | 485 | 
                })  | 
            
| 481 | 486 | 
                 | 
            
| 482 | 
                -    return response(data={})
               | 
            |
| 487 | 
                + return response()  | 
            
                @@ -63,7 +63,7 @@ class MemberActivitySigninInfoAdmin(admin.ModelAdmin):  | 
            ||
| 63 | 63 | 
                 | 
            
| 64 | 64 | 
                 | 
            
| 65 | 65 | 
                class MemberActivityGroupShareInfoAdmin(admin.ModelAdmin):  | 
            
| 66 | 
                -    list_display = ('group_share_id', 'share_user_id', 'click_user_id', 'open_gid', 'activity_id', 'title', 'is_integral', 'integral', 'status', 'created_at', 'updated_at')
               | 
            |
| 66 | 
                +    list_display = ('group_share_id', 'activity_id', 'share_user_id', 'click_user_id', 'open_gid', 'title', 'is_integral', 'integral', 'status', 'created_at', 'updated_at')
               | 
            |
| 67 | 67 | 
                     list_filter = ('is_integral', 'status')
               | 
            
| 68 | 68 | 
                 | 
            
| 69 | 69 | 
                 | 
            
                @@ -298,6 +298,7 @@ class MemberActivityInfo(BaseModelMixin):  | 
            ||
| 298 | 298 | 
                 | 
            
| 299 | 299 | 
                integral = models.IntegerField(_(u'integral'), default=0, help_text=u'会员积分')  | 
            
| 300 | 300 | 
                group_share_integral = models.IntegerField(_(u'group_share_integral'), default=0, help_text=u'群组分享会员积分')  | 
            
| 301 | 
                + group_share_max_integral = models.IntegerField(_(u'group_share_max_integral'), default=0, help_text=u'群组分享会员积分单人上限')  | 
            |
| 301 | 302 | 
                 | 
            
| 302 | 303 | 
                image = models.ImageField(_(u'image'), upload_to=upload_path, blank=True, null=True, help_text=u'活动内容图片')  | 
            
| 303 | 304 | 
                 | 
            
                @@ -311,10 +312,10 @@ class MemberActivityInfo(BaseModelMixin):  | 
            ||
| 311 | 312 | 
                share_img_link = models.CharField(_(u'share_img_link'), max_length=255, blank=True, null=True, help_text=u'活动图片分享')  | 
            
| 312 | 313 | 
                share_h5_link = models.CharField(_(u'share_h5_link'), max_length=255, blank=True, null=True, help_text=u'活动H5分享')  | 
            
| 313 | 314 | 
                 | 
            
| 314 | 
                - position = models.IntegerField(_(u'position'), default=1, help_text=u'排序', db_index=True)  | 
            |
| 315 | 
                -  | 
            |
| 316 | 315 | 
                is_signup = models.BooleanField(_(u'is_signup'), default=True, help_text=u'是否有报名功能')  | 
            
| 317 | 316 | 
                 | 
            
| 317 | 
                + position = models.IntegerField(_(u'position'), default=1, help_text=u'排序', db_index=True)  | 
            |
| 318 | 
                +  | 
            |
| 318 | 319 | 
                class Meta:  | 
            
| 319 | 320 | 
                verbose_name = _(u'会员活动信息')  | 
            
| 320 | 321 | 
                verbose_name_plural = _(u'会员活动信息')  | 
            
                @@ -462,13 +463,13 @@ class MemberActivityGroupShareInfo(BaseModelMixin):  | 
            ||
| 462 | 463 | 
                 | 
            
| 463 | 464 | 
                group_share_id = ShortUUIDField(_(u'group_share_id'), max_length=32, blank=True, null=True, help_text=u'活动群组分享唯一标识', db_index=True, unique=True)  | 
            
| 464 | 465 | 
                 | 
            
| 466 | 
                + activity_id = models.CharField(_(u'activity_id'), max_length=32, blank=True, null=True, help_text=u'活动唯一标识', db_index=True)  | 
            |
| 467 | 
                +  | 
            |
| 465 | 468 | 
                share_user_id = models.CharField(_(u'share_user_id'), max_length=32, blank=True, null=True, help_text=u'分享用户唯一标识', db_index=True)  | 
            
| 466 | 469 | 
                click_user_id = models.CharField(_(u'click_user_id'), max_length=32, blank=True, null=True, help_text=u'点击用户唯一标识', db_index=True)  | 
            
| 467 | 470 | 
                 | 
            
| 468 | 471 | 
                open_gid = models.CharField(_(u'open_gid'), max_length=32, blank=True, null=True, help_text=u'群组唯一标识', db_index=True)  | 
            
| 469 | 472 | 
                 | 
            
| 470 | 
                - activity_id = models.CharField(_(u'activity_id'), max_length=32, blank=True, null=True, help_text=u'活动唯一标识', db_index=True)  | 
            |
| 471 | 
                -  | 
            |
| 472 | 473 | 
                title = models.CharField(_(u'title'), max_length=255, blank=True, null=True, help_text=u'活动名称')  | 
            
| 473 | 474 | 
                 | 
            
| 474 | 475 | 
                is_integral = models.BooleanField(_(u'is_integral'), default=False, help_text=u'是否有积分')  |